package com.maozw.aop.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author
 * @Title: ${DynamicAspect}
 * @Package ${DynamicAspect}
 * @Description: ${动态数据切换的切面，切 *** 层，通过***层方法名判断使用哪个数据，实现数据切换}
 * @date 2018/3/2318:42
 */
@Aspect
@Component
public class DynamicAspect {
    private static final Logger logger = LoggerFactory.getLogger(DynamicAspect.class);



    @Pointcut("@annotation(com.maozw.aop.annotation.Maoge)")
    public void daoAspect() {
    }

    //环绕增强
    @Around("daoAspect()")
    public void asAround(ProceedingJoinPoint pj){
        System.out.println("这是环绕前置增强");
        try {
           // pj.proceed();
        } catch (Throwable e) {
            //抓捕异常
            e.printStackTrace();
        }
        System.out.println("这是环绕后置增强");
    }

//    @Before("daoAspect()")
//    public void switchDataSource(JoinPoint point) {
//            logger.info("Switch DataSource to [{}] in Method [{}]");
//    }
//
//    @After("daoAspect())")
//    public void restoreDataSource(JoinPoint point) {
//        logger.info("Restore DataSource to [{}] in Method [{}]");
//    }

}
